package com.doit.day03;

import scala.Int;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class _02_比较器 {
    public static void main(String[] args) {
        ChiGe chiGe1 = new ChiGe(1, "zss1", 18, "gender");
        ChiGe chiGe2 = new ChiGe(2, "zss2", 16, "gender");
        ChiGe chiGe3 = new ChiGe(3, "zss3", 15, "gender");
        ChiGe chiGe4 = new ChiGe(4, "zss4", 17, "gender");
        ChiGe chiGe5 = new ChiGe(5, "zss5", 19, "gender");

        ArrayList<ChiGe> list = new ArrayList<>();
        list.add(chiGe1);
        list.add(chiGe2);
        list.add(chiGe3);
        list.add(chiGe4);
        list.add(chiGe5);

        //驰哥  给我比较一下集合中的所有驰哥，找个最大的给我

        //你啥都不给我，我按照啥排啊，所以需要给他一个比较器，去对各个对象进行比较
        Collections.sort(list/*, new Comparator<ChiGe>() {//传的比较规则
            @Override
            public int compare(ChiGe o1, ChiGe o2) {
                return o1.getAge() - o2.getAge();
            }
        }*/);

        for (ChiGe chiGe : list) {
            System.out.println(chiGe);
        }


        ArrayList<Integer> list1 = new ArrayList<>();
        list1.add(10);
        list1.add(12);
        list1.add(11);
        list1.add(15);
        list1.add(14);

        //字符串，int，这些天生就是可比较的，为啥人家就是可比较的  他实现了comparable 接口  ==》 比较规则
        Collections.sort(list1);


    }
}
